<!--管理员登陆页面-->
<template>
  <!--  <div :style="'background-image:url('+'../../static/jpg/login.jpg'+');background-size: 100% 100%'">-->

  <div style="width: 1950px">
    <!--    <div :style="{backgroundImage:url('../../static/jpg/login.jpg')}">-->
    <img src="../../static/jpg/login.jpg" style="width: 100%">
    <div
        style="width: 450px; background: #fff; margin: -700px 1055px; padding: 30px 60px;box-shadow: 0px 2px 12px 0px rgba(0,0,0,0.1);">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-row>
          <el-form-item label="用户名" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="密码" prop="password">
            <el-input v-model="ruleForm.password"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button type="primary"
                       @click="submitForm('ruleForm') ">登录
            </el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: '',
        password: ''
      },
      rules: {
        name: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 4, max: 15, message: '长度在 4 到 15 个字符', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 4, max: 15, message: '长度在 4 到 15 个字符', trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = 'http://localhost:9081/admins/login';
          console.log('url = ' + url);
          let formData = this.qs.stringify(this.ruleForm);
          this.axios.post(url, formData).then((response) => {
            let responseBody = response.data;

            if (responseBody.state == 20000) {
              this.$message({
                message: '登录成功！',
                type: 'success'
              });
              console.log(responseBody.state)
              let jwt = responseBody.data;
              console.log("登陆成功!服务器相应的JWT=" + jwt);
              localStorage.setItem("jwt",jwt);
              console.log(localStorage.getItem("jwt"))
              this.turntoAdmin();
            } else if (responseBody.state == 20001) {
              this.turntoStaff();
            } else {
              this.$message.error('登录失败!用户名或密码错误！');
            }

          });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    turntoAdmin() {
      console.log('跳转后台管理页面!')
      this.$router.push({path: '/homeview', query: {name: this.ruleForm.name}})
    },
    turntoStaff() {
      console.log('跳转员工页面!')
      this.$router.push({path: '/other/temp/WorkingView', query: {name: this.ruleForm.name}})
    },
  }
}
</script>

<style>
body {
  font-size: 14px;
  line-height: 1.42857143;
  background-color: #fff;

}

/*#img1{*/
/*  z-index: auto;*/
/*  background-image: url(../../static/jpg/login.jpg);*/
/*  background-size: 100%;*/
/*}*/
</style>
